export default function request(url,data,header,method='get',showLoadding=true){
    if(showLoadding){
        uni.showLoading({
            title: '解析中'
        });
    }
    return new Promise(async (resolve,reject)=>{
        if(url.includes('http')){
            uni.request({
                url,
                data,
                method,
                header,
                timeout:60000*10*20,
                success: (res) => {

                    resolve(res.data)
                },
                fail:(err)=>{
                    reject(err)
                    uni.showToast({
                        title: '解析失败'
                    });
                },
                complete:  ()=>{
                    if(showLoadding){
                        uni.hideLoading();
                    }
                }
            });
        }else{
            try{
                const res = await  wx.cloud.callContainer({
                    "config": {
                        "env": "prod-2go88w4r080945f9"
                    },
                    "path": url,
                    "header": {
                        "X-WX-SERVICE": "koa-t5t8",
                        ...header
                    },
                    "method": method,
                    "data": data
                });
                resolve(res.data)
            }catch (err){
                reject(err)
                uni.showToast({
                    title: '解析失败'
                });
            }
            if(showLoadding){
                uni.hideLoading();
            }
        }





    })
}
